package com.heng.futureDemo;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ACompletableFutureAPIDemo12 {
    public static void main(String[] args) {
        System.out.println(CompletableFuture.supplyAsync(()->"resultA").thenRun(()->{}).join());
        System.out.println(CompletableFuture.supplyAsync(()->"resultA").thenAccept(r-> System.out.println(r)).join());
        System.out.println(CompletableFuture.supplyAsync(()->"resultA").thenApply(r-> r + " resultB").join());
    }
//消费型接口
    private static void m2() {
        CompletableFuture.supplyAsync(() -> {
            return 1;
        }).thenApply(f -> {
            return f + 2;
        }).thenApply(f-> {
            return f + 3;
        }).thenAccept(System.out::println);
    }

    private static void m1() {
        CompletableFuture.supplyAsync(() -> {
            return 1;
        }).thenApply(f -> {
            return f + 2;
        }).thenApply(f-> {
            return f + 3;
        }).thenAccept(r -> {//消费
                System.out.println("---计算结果： " + r);
        });
    }
}
